package javacode.chapter07.homework;

import java.util.Random;

public class Homework14 {
    public static void main(String[] args) {
        Person person = new Person("Tom",0,0,0);
        int count = 10;//猜拳次数
        Random rd1 = new Random();
        Random rd2 = new Random();

        for (int i = 0; i < count; i++) {
            int r1 = rd1.nextInt(3);//Tom出的拳
            int r2 = rd2.nextInt(3);//电脑出的拳
            //平局
            if (r1==r2){
                System.out.println(person.name+"出"+r1+",电脑出"+r2+",平局");
                person.setDrawCount(person.drawCount+1);
            }else if (r1==0&&r2==1 || r1==1&&r2==2 || r1==2&&r2==0){
                System.out.println(person.name+"出"+r1+",电脑出"+r2+","+person.name+"赢");
                person.setWinCount(person.winCount+1);
            }else if (r2==0&&r1==1 || r2==1&&r1==2 || r2==2&&r1==0){
                System.out.println(person.name+"出"+r1+",电脑出"+r2+","+"电脑赢");
                person.setLostCount(person.lostCount+1);
            }else{
                System.out.println("r1="+r1+",r2=" + r2);
            }
        }
        System.out.println(person.name+"赢："+ person.winCount);
        System.out.println(person.name+"输："+ person.lostCount);
        System.out.println(person.name+"平局："+ person.drawCount);
    }
}

/**
 * 有个人Tom设计他的成员变量，成员方法，可以电脑猜拳，
 * 电脑每次都会随机生成0，1，2
 * 0表示石头， 1表示剪刀， 2表示布
 * 并要可以显示Tom的输赢次数（清单）
 */

class Person{
    String name;
    int winCount;
    int lostCount;
    int drawCount;//平局次数



    public Person() {
    }

    public Person(String name, int drawCount){
        this.name = name;
        this.drawCount = drawCount;
    }

    public Person(String name, int winCount, int lostCount, int drawCount) {
        this.name = name;
        this.winCount = winCount;
        this.lostCount = lostCount;
        this.drawCount = drawCount;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getWinCount() {
        return winCount;
    }

    public void setWinCount(int winCount) {
        this.winCount = winCount;
    }

    public int getLostCount() {
        return lostCount;
    }

    public void setLostCount(int lostCount) {
        this.lostCount = lostCount;
    }

    public int getDrawCount() {
        return drawCount;
    }

    public void setDrawCount(int drawCount) {
        this.drawCount = drawCount;
    }
}